package cn.sxt.yxl.question.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.sxt.yxl.common.util.PageInfoUtil;
import cn.sxt.yxl.question.dao.IAColumnsDao;
import cn.sxt.yxl.question.pojo.AColumns;
import cn.sxt.yxl.question.service.IAColumnsService;

@Service("columnsService")
public class AColumnsServiceImpl implements IAColumnsService{

	@Resource
	private IAColumnsDao columnsDao;
	//查询单个管理员
	@Override
	public AColumns findOne(Map<String, Object> map) {
		
		return columnsDao.findOne(map);
	}
	
	//添加管理员
	@Override
	public JSONObject saveOne(AColumns columns) {
		
		int res = columnsDao.saveOne(columns);
		if(res>0){
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", columns.getId());
			dataJSON.put("effectCount", res);
			JSONObject resultJSON = new JSONObject();
			resultJSON.put("code", 0);
			resultJSON.put("info", "成功");
			resultJSON.put("data", dataJSON);
			return resultJSON;
		}else{
			JSONObject resultJSON = new JSONObject();
			resultJSON.put("code", 1);
			resultJSON.put("info", "失败");
			return resultJSON;
		}
	}
	@Override
	public JSONObject updateOne(AColumns columns) {
		int res = columnsDao.updateOne(columns);
		if(res>0){
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", columns.getId());
			dataJSON.put("effectCount", res);
			JSONObject resultJSON = new JSONObject();
			resultJSON.put("code", 0);
			resultJSON.put("info", "成功");
			resultJSON.put("data", dataJSON);
			return resultJSON;
		}else{
			JSONObject resultJSON = new JSONObject();
			resultJSON.put("code", 1);
			resultJSON.put("info", "失败");
			return resultJSON;
		}
	}
	@Override
	public JSONObject deleteOne(AColumns columns) {
		int res = columnsDao.deleteOne(columns);
		if(res>0){
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", columns.getId());
			dataJSON.put("effectCount", res);
			JSONObject resultJSON = new JSONObject();
			resultJSON.put("code", 0);
			resultJSON.put("info", "成功");
			resultJSON.put("data", dataJSON);
			return resultJSON;
		}else{
			JSONObject resultJSON = new JSONObject();
			resultJSON.put("code", 1);
			resultJSON.put("info", "失败");
			return resultJSON;
		}
	}

	@Override
	public List<AColumns> findMany(Map<String, Object> map,PageInfoUtil pageInfoUtil) {
		if(pageInfoUtil!=null){
			Page<AColumns> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			List<AColumns> list = columnsDao.findMany(map);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal()+""));
			return list;
		}
		
		
		return columnsDao.findMany(map);
	}

	
}
